package com.geeksaga.dao.ibatis.oracle;

import java.util.List;


import org.springframework.dao.DataAccessException;
import org.springframework.stereotype.Repository;

import com.geeksaga.dao.BbsRateDao;
import com.geeksaga.dao.ibatis.BaseIBatisDao;
import com.geeksaga.domain.BbsRate;

/**
 * @author newbie
 * @since 0.1
 */
@Repository
public class BbsRateDaoImpl extends BaseIBatisDao implements BbsRateDao {

    /* (non-Javadoc)
     * @see com.geeksaga.dao.BbsRateDao#add(com.geeksaga.domain.BbsRate)
     */
    public BbsRate add(BbsRate bbsRate) throws DataAccessException {
        return (BbsRate) getSqlMapClientTemplate().insert("BBS_RATE.add", bbsRate);
    }

    /* (non-Javadoc)
     * @see com.geeksaga.dao.BbsRateDao#exists(com.geeksaga.domain.Bbs)
     */
    @SuppressWarnings("unchecked")
    public boolean exists(BbsRate bbsRate) throws DataAccessException {
        List<BbsRate> list = (List<BbsRate>) getSqlMapClientTemplate().queryForList("BBS_RATE.find", bbsRate);
        
        if(list == null || (list != null && list.size() == 0))
            return false;
        else
            return true;
    }
    
    /* (non-Javadoc)
     * @see com.geeksaga.dao.BbsRateDao#calculate(com.geeksaga.domain.Bbs)
     */
    public BbsRate calculate(BbsRate bbsRate) throws DataAccessException {
        return (BbsRate) getSqlMapClientTemplate().queryForObject("BBS_RATE.calculate", bbsRate);
    }    
}